using UnityEngine;

[RequireComponent(typeof(AttackProperties))]
public class AtackStay : MonoBehaviour
{
    [SerializeField] private AttackProperties _attackProperties;
    [SerializeField] private Attacked _attacked;

    private void Awake()
    {
        _attackProperties = GetComponent<AttackProperties>();
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        _attacked = collision.gameObject.GetComponent<Attacked>();
    }

    private void OnTriggerStay2D(Collider2D collision)
    {
        if (_attacked != null) _attacked.TakeDamage(_attackProperties.DamageOut());
    }
}